#! /usr/bin/env python
"""
Create a QuickTime movie from a sequence of still images on Windows.

Usage: python qt_movie_from_stills.py sourcepath destpath [framerate]

Use FULLY-QUALIFIED Windows file paths. Relative paths don't work well
inside QuickTime -- it is likely to fail with no error report from QT.

You must have the PyWin32 COM interface installed,
see http://sourceforge.net/projects/pywin32/

Author: Chip Chapin <cchapin@gmail.com>
For More Info: http://code.google.com/p/seq-to-qt/

Acknowledgements:
  I originally wrote this as a JScript+WSH script based on a post by
  Luc-Eric Rousseau (XSIBlog 2006, http://www.xsi-blog.com/archives/103).
  His was in turn based on sample code by John Cromie that accompanied
  his book "QuickTime for .NET and COM Developers"
  (Elsevier 2006, http://www.skylark.ie/qt4.net/samplecode.asp).

Last Update: 2010-02-03

TODO: Some sort of progress indicator during the initial rendering stage.
"""
import seq_to_qt
import os

def usage(message=None):
    """Print usage message and exit."""
    if message:
        print message
    print "Usage: qt_movie_from_stills.py sourcepath destpath [framerate]"
    print "Hint: Avoid relative paths, use fully-qualified Windows paths"
    print "(e.g. C:\\a\\b\\c.jpg)."
    sys.exit(2)

def main(argv):
    """Main Program"""
    if (len(argv) < 3):
        usage()
    sourcePath = argv[1]
    destPath = argv[2]
    if (len(argv) >= 4):
        frameRate = argv[3]
    else:
        frameRate = seq_to_qt.DEFAULT_FRAME_RATE
    print "FrameRate: " + frameRate

    if not seq_to_qt.file_exists(sourcePath):
        usage("Missing source file '" + sourcePath +"'")
    if seq_to_qt.file_exists(destPath):
        # .mov files take a long time to create.  Avoid
        # overwriting one by mistake.
        usage("Will not overwrite destination file '" + destPath + "'")
    if not seq_to_qt.check_file_folder(destPath):
        usage("Unusable destination file path '" + destPath +"'")
    seq_to_qt.qt_movie_from_stills(sourcePath, destPath, frameRate)

if __name__ == "__main__":
    import sys
    main(sys.argv)
